package pl.darbat.photogallery;

import android.util.Log;

public class Debug {
	public static final boolean DEBUG_ALL = true;
	
	public static boolean CATEGORIESACTIVITY = false;
	public static boolean CATEGORYGRIDACTIVITY = false;
	public static boolean PHOTOACTIVITY = false;
	public static boolean IMAGEDOWNLOAD = false;
	public static boolean PHOTOLISTADAPTER = false;
	public static boolean HTMLPARSER = false;
	public static boolean HTMLDOWNLOADER = false;
	public static boolean LISTDOWNLOADER = false;
	public static boolean DEBUG = false;
	public static final String TAG = "Debug";
	static {
		if(DEBUG_ALL){
			CATEGORIESACTIVITY = true;
			CATEGORYGRIDACTIVITY = true;
			PHOTOACTIVITY = true;
			IMAGEDOWNLOAD = true;
			PHOTOLISTADAPTER = true;
			HTMLPARSER = true;
			HTMLDOWNLOADER = true;
			LISTDOWNLOADER = true;
		}
	}
	
	public static Thread createMemoryStatusThread(final MemoryStatusListener result) {
		return new Thread() {
			boolean running = true;

			@Override
			public void destroy() {
				super.destroy();
				if(Debug.DEBUG) Log.v("MemoryStatus", "destroy");
				running = false;
			}

			@Override
			public void run() {
				if(Debug.DEBUG) Log.v("MemoryStatus", "run");				
				while (running) {
					//String usedMegsString = String.format("Memory Used: %d kB", readMemoryUsage());
					//result.onMemoryStatus(usedMegsString);
					result.onMemoryStatus("Memory used: " + readMemoryUsage() + " kB");
					try {
						sleep(1000);
					} catch (InterruptedException e) {
						Log.e(TAG, "", e);
					}
				}
			}

		};
	}
		
	public static int readMemoryUsage(){
		return (int) (android.os.Debug.getNativeHeapAllocatedSize() / 1048L);
	}
	
	public interface MemoryStatusListener {
		public void onMemoryStatus(String status);
	}






}